package com.grablist.feihu.grablist.ui.actviity.user.biz;

import android.content.Context;

import com.grablist.feihu.grablist.base.BaseBiz;
import com.grablist.feihu.grablist.base.BaseResp;
import com.grablist.feihu.grablist.base.BaseRespNew;
import com.grablist.feihu.grablist.bean.CustomInfo;
import com.grablist.feihu.grablist.bean.SelectVoiceInfo;
import com.grablist.feihu.grablist.comm.BaseSubscribe2;
import com.grablist.feihu.grablist.comm.BaseSubscribe2New;
import com.grablist.feihu.grablist.comm.RetrofitHelp;
import com.grablist.feihu.grablist.comm.RetrofitHelpNew;

import okhttp3.RequestBody;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * Created by admin on 2017/12/2.
 */

public class CustomBiz extends BaseBiz {
    /**
     * 添加收藏信息
     *
     * @param userCode
     * @param userCode
     * @param callback
     */
    public void addColl(String userCode, String studentCode, final BaseBiz.Callback<CustomInfo> callback) {
        com.add(RetrofitHelp.getSecretApi().addMyCollection(userCode, studentCode)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new BaseSubscribe2<BaseResp<CustomInfo>>() {

                    @Override
                    public void onSuccess(Object obj) {
                        callback.onSuccess((CustomInfo) obj);
                    }

                    @Override
                    public void onFailure(Object obj) {
                        callback.onFailure((CustomInfo) obj);
                    }
                })
        );
    }

    /**
     * 删除收藏信息
     *
     * @param userCode
     * @param userCode
     * @param callback
     */
    public void delColl(String userCode, String uid, final BaseBiz.Callback<Object> callback) {
        com.add(RetrofitHelp.getSecretApi().delMyCollection(userCode, uid)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new BaseSubscribe2<BaseResp<Object>>() {

                    @Override
                    public void onSuccess(Object obj) {
                        callback.onSuccess((Object) obj);
                    }

                    @Override
                    public void onFailure(Object obj) {
                        callback.onFailure((Object) obj);
                    }
                })
        );
    }

    /**
     * 获取信息
     *
     * @param userCode
     * @param userCode
     * @param callback
     */
    public void getIndo(String userCode, String studentCode, String useable, final BaseBiz.Callback<CustomInfo> callback) {
        com.add(RetrofitHelp.getSecretApi().studentInfo(userCode, studentCode, useable)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new BaseSubscribe2<BaseResp<CustomInfo>>() {

                    @Override
                    public void onSuccess(Object obj) {
                        callback.onSuccess((CustomInfo) obj);
                    }

                    @Override
                    public void onFailure(Object obj) {
                        callback.onFailure((CustomInfo) obj);
                    }
                })
        );
    }

    /**
     * 获取录音
     *
     * @param jsonStr
     * @param callback
     */
    public void selectVoice(Context context, RequestBody jsonStr, final BaseBiz.Callback<SelectVoiceInfo> callback) {
        com.add(RetrofitHelpNew.getSecretApi(context).selectVoice(jsonStr)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new BaseSubscribe2New<BaseRespNew<SelectVoiceInfo>>() {

                    @Override
                    public void onSuccess(Object obj) {
                        callback.onSuccess((SelectVoiceInfo) obj);
                    }

                    @Override
                    public void onFailure(Object obj) {
                        callback.onFailure((SelectVoiceInfo) obj);
                    }
                })
        );
    }

    /**
     * 生成订单
     *
     * @param studentCode
     * @param orderAmount
     * @param callback
     */
    public void createOrder(String userCode, String studentCode, String orderAmount, final BaseBiz.Callback<Object> callback) {
        com.add(RetrofitHelp.getSecretApi().createStudentOrder(userCode, studentCode, orderAmount)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new BaseSubscribe2<BaseResp<Object>>() {

                    @Override
                    public void onSuccess(Object obj) {
                        callback.onSuccess((Object) obj);
                    }

                    @Override
                    public void onFailure(Object obj) {
                        callback.onFailure((Object) obj);
                    }
                })
        );
    }

}
